package v1

import (
	"fmt"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	resp "gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
)

// @Tags ArticleClass
// @Summary 创建ArticleClass
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ArticleClass true "创建ArticleClass"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /articleClass/createArticleClass [post]
func CreateArticleClass(c *gin.Context) {
	var articleClass model.ArticleClass
	_ = c.ShouldBindJSON(&articleClass)
	err := service.CreateArticleClass(articleClass)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("创建失败，%v", err), c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags ArticleClass
// @Summary 删除ArticleClass
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ArticleClass true "删除ArticleClass"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /articleClass/deleteArticleClass [delete]
func DeleteArticleClass(c *gin.Context) {
	var articleClass model.ArticleClass
	_ = c.ShouldBindJSON(&articleClass)
	err := service.DeleteArticleClass(articleClass)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("删除失败，%v", err), c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags ArticleClass
// @Summary 批量删除ArticleClass
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ArticleClass"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /articleClass/deleteArticleClassByIds [delete]
func DeleteArticleClassByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	err := service.DeleteArticleClassByIds(IDS)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("删除失败，%v", err), c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags ArticleClass
// @Summary 更新ArticleClass
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ArticleClass true "更新ArticleClass"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /articleClass/updateArticleClass [put]
func UpdateArticleClass(c *gin.Context) {
	var articleClass model.ArticleClass
	_ = c.ShouldBindJSON(&articleClass)
	err := service.UpdateArticleClass(&articleClass)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("更新失败，%v", err), c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags ArticleClass
// @Summary 用id查询ArticleClass
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ArticleClass true "用id查询ArticleClass"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /articleClass/findArticleClass [get]
func FindArticleClass(c *gin.Context) {
	var articleClass model.ArticleClass
	_ = c.ShouldBindQuery(&articleClass)
	err, rearticleClass := service.GetArticleClass(articleClass.ID)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("查询失败，%v", err), c)
	} else {
		response.OkWithData(gin.H{"rearticleClass": rearticleClass}, c)
	}
}

// @Tags ArticleClass
// @Summary 分页获取ArticleClass列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.ArticleClassSearch true "分页获取ArticleClass列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /articleClass/getArticleClassList [get]
func GetArticleClassList(c *gin.Context) {
	var pageInfo request.ArticleClassSearch
	_ = c.ShouldBindQuery(&pageInfo)
	err, list, total := service.GetArticleClassInfoList(pageInfo)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("获取数据失败，%v", err), c)
	} else {
		response.OkWithData(resp.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, c)
	}
}
